package com.zx.tradeclient.ctrl.index5;

import java.util.ArrayList;
import java.util.List;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;

import com.zx.base.ctrl.BaseActivity;
import com.zx.base.util.ActivityTaskManager;
import com.zx.base.widget.SlidingPage;
import com.zx.base.widget.SlidingPage.SlidingPagerAdapter;
import com.zx.base.widget.SlidingPage.ViewPagerSelectListener;
import com.zx.tradeclient.R;

public class FavoritePageActivity extends BaseActivity {
	/** Called when the activity is first created. */

	private Button header_left, header_right;
	private FavoriteList fav_1, fav_2, fav_3, fav_4, fav_5;
	private SlidingPage page;
	private LinearLayout page_layout;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.listindex);

		if (!(ActivityTaskManager.getInstance().containsName("Index2Activity"))) {
			ActivityTaskManager.getInstance().putActivity("Index2Activity",
					this);
		}

		init();
	}

	private void init() {
		LayoutInflater mInflater = getLayoutInflater();
		setHeader(0);

		String[] titles = new String[] { "新闻收藏", "产品收藏", "供应收藏", "求购收藏", "企业收藏" };
		page = new SlidingPage(this, 5, R.drawable.page_slider_5);
		page.setTitles(titles);

		page_layout = (LinearLayout) findViewById(R.id.list_main_layout);
		page_layout.addView(page);

		final List<View> listViews = new ArrayList<View>();
		listViews.add(mInflater.inflate(R.layout.list, null));
		listViews.add(mInflater.inflate(R.layout.list, null));
		listViews.add(mInflater.inflate(R.layout.list, null));
		listViews.add(mInflater.inflate(R.layout.list, null));
		listViews.add(mInflater.inflate(R.layout.list, null));
		page.getViewPager().setAdapter(new SlidingPagerAdapter(listViews));

		page.setViewPageSelectedListener(new ViewPagerSelectListener() {

			@Override
			public void pageSelected(int current) {
				View view = listViews.get(current);
				switch (current) {
				case 0:
					if (fav_1 == null)
						fav_1 = new FavoriteList(FavoritePageActivity.this,
								view, 1);
					break;
				case 1:
					if (fav_2 == null)
						fav_2 = new FavoriteList(FavoritePageActivity.this,
								view, 2);
					break;
				case 2:
					if (fav_3 == null)
						fav_3 = new FavoriteList(FavoritePageActivity.this,
								view, 3);
					break;
				case 3:
					if (fav_4 == null)
						fav_4 = new FavoriteList(FavoritePageActivity.this,
								view, 4);
					break;
				case 4:
					if (fav_5 == null)
						fav_5 = new FavoriteList(FavoritePageActivity.this,
								view, 5);
					break;
				default:
					break;
				}

			}
		});

		page.getViewPager().setCurrentItem(0, false);
		page.getViewPageSelectedListener().pageSelected(0);

	}

	public void onClick(View v) {
		// TODO Auto-generated method stub
		if (v == header_left) {

		} else if (v == header_right) {

		}

	}

}